package com.ssy.lingxi.marketing.controller.feign;

import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.marketing.api.model.request.CartOrderReq;
import com.ssy.lingxi.marketing.api.model.request.CouponConsumeReq;
import com.ssy.lingxi.marketing.api.model.request.CouponDetailConsumeReq;
import com.ssy.lingxi.marketing.api.model.request.CouponQueryReq;
import com.ssy.lingxi.marketing.api.model.response.CartOrderResp;
import com.ssy.lingxi.marketing.api.model.response.CouponInfoResp;
import com.ssy.lingxi.marketing.service.feign.ICouponFeignService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * 优惠券feign接口
 * @author yzc
 * @version 2.0.0
 * @date 2021/11/3
 */
@RestController
public class CouponFeignController {

    @Resource
    private ICouponFeignService couponFeignService;

    /**
     * 内部接口 - 校验优惠券可用
     **/
    @PostMapping(value = "/marketing/coupon/feign/order/check")
    public Wrapper<List<CartOrderResp>> checkCouponAvailable(@RequestBody @Valid CartOrderReq req) {
        return couponFeignService.checkCouponAvailable(req);
    }

    /**
     * 内部接口 - 提交订单后消耗优惠券
     **/
    @PostMapping(value = "/marketing/coupon/feign/order/save")
    public Wrapper<Void> consumeCoupon(@RequestBody @Valid CouponConsumeReq req) {
        return couponFeignService.consumeCoupon(req);
    }

    /**
     * 内部接口 - 取消订单后返还优惠券
     **/
    @PostMapping(value = "/marketing/coupon/feign/order/cancel")
    public Wrapper<Void> returnCoupon(@RequestBody @Valid List<CouponDetailConsumeReq> req) {
        return couponFeignService.returnCoupon(req);
    }

    /**
     * 内部接口 - 根据优惠券ids，查询券码
     **/
    @PostMapping(value = "/marketing/coupon/feign/detail/list")
    public Wrapper<List<CouponInfoResp>> getCouponDetailListByIds(@RequestBody @Valid CouponQueryReq req){
        return couponFeignService.getCouponDetailListByIds(req);
    }
}
